#include "signal.h"
#include "stdio.h"
static int is_running = 1;
static void use_resource()
{
    printf("use resource\n");
}
static void free_resource()
{
    printf("free resource\n");
}
static void sign_handler(int signum)
{
    if (signum == SIGINT)
    {
        printf("收到ctrl+c结束的信号\n");
        is_running = 0;
    }
    else if (signum == SIGTERM)
    {
        printf("收到kill结束的信号\n");
    is_running = 0;
    }
    
}
int main(int argc, char const *argv[])
{
    //注册信号处理函数
    signal(SIGINT, sign_handler);
    signal(SIGTERM, sign_handler);

    use_resource();
    while (is_running)
    {
        printf("程序正在运行中\n");
        sleep(1);
    }

    free_resource();
    /* code */
    return 0;
}
